unit F_Alarm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, CheckLst, ComCtrls, JvComponentBase,
  JvFormPlacement;

type
  TFormAlarm = class(TForm)
    Button_Ok: TBitBtn;
    Edit_Time: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    List_DN: TCheckListBox;
    Check_AlarmOff: TCheckBox;
    FormStorage: TJvFormStorage;
    CheckBox_Now: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure CheckBox_NowClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    Procedure SetIgnore;
    Function GetIgnore:TDateTime;
  end;

var
  FormAlarm: TFormAlarm;

implementation

{$R *.dfm}

Uses F_Main;

Procedure TFormAlarm.SetIgnore;
var s:string;
    i:TDateTime;
begin
  s:=Path+'ignore.dte';
  i:=Date;
  with TFileStream.Create(s,fmCreate) do begin
    WriteBuffer(i,SizeOf(i));
    Free;
  end;
end;

Function TFormAlarm.GetIgnore:TDateTime;
var s:string;
    i:TDateTime;
begin
  i:=0;
  s:=Path+'ignore.dte';
  if FileExists(s) then begin
    with TFileStream.Create(s,fmOpenRead) do begin
      ReadBuffer(i,SizeOf(i));
      Free;
    end;
  end;
  Result:=i;
end;

procedure TFormAlarm.CheckBox_NowClick(Sender: TObject);
var s:string;
    i:TDateTime;
begin
  s:=Path+'ignore.dte';
  if CheckBox_Now.Checked then SetIgnore
                          else if FileExists(s) then DeleteFile(s);
end;

procedure TFormAlarm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FormStorage.StoredValues.Values['p1'].Value:=List_DN.Checked[0];
  FormStorage.StoredValues.Values['p2'].Value:=List_DN.Checked[1];
  FormStorage.StoredValues.Values['p3'].Value:=List_DN.Checked[2];
  FormStorage.StoredValues.Values['p4'].Value:=List_DN.Checked[3];
  FormStorage.StoredValues.Values['p5'].Value:=List_DN.Checked[4];
  FormStorage.StoredValues.Values['p6'].Value:=List_DN.Checked[5];
  FormStorage.StoredValues.Values['p7'].Value:=List_DN.Checked[6];
  FormStorage.SaveFormPlacement;
  FormMain.AppIniFileStorage.Flush;
end;

procedure TFormAlarm.FormShow(Sender: TObject);
begin
  FormMain.AppIniFileStorage.Reload;
  FormStorage.RestoreFormPlacement;
  List_DN.Checked[0]:=FormStorage.StoredValues.Values['p1'].Value;
  List_DN.Checked[1]:=FormStorage.StoredValues.Values['p2'].Value;
  List_DN.Checked[2]:=FormStorage.StoredValues.Values['p3'].Value;
  List_DN.Checked[3]:=FormStorage.StoredValues.Values['p4'].Value;
  List_DN.Checked[4]:=FormStorage.StoredValues.Values['p5'].Value;
  List_DN.Checked[5]:=FormStorage.StoredValues.Values['p6'].Value;
  List_DN.Checked[6]:=FormStorage.StoredValues.Values['p7'].Value;
end;

end.
